<?php

namespace common\modules\ad\models;

use common\behaviors\TimestampBehavior;
use common\behaviors\UserRecordBehavior;
use common\components\ActiveRecord;
use Yii;

/**
 * This is the model class for table "ad_position".
 *
 * @property integer $id
 * @property string $name
 * @property integer $ad_width
 * @property integer $ad_height
 * @property string $description
 * @property string $template
 * @property integer $created_at
 * @property integer $updated_at
 * @property integer $created_by
 * @property integer $updated_by
 */
class Position extends ActiveRecord
{

    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'ad_position';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['ad_width', 'ad_height'], 'integer'],
            [['created_at', 'updated_at', 'created_by', 'updated_by'], 'safe'],
            [['template'], 'required'],
            [['template'], 'string'],
            [['name'], 'string', 'max' => 60],
            [['description'], 'string', 'max' => 255]
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app/ad', 'ID'),
            'name' => Yii::t('app/ad', 'Name'),
            'ad_width' => Yii::t('app/ad', 'Ad Width'),
            'ad_height' => Yii::t('app/ad', 'Ad Height'),
            'description' => Yii::t('app/ad', 'Description'),
            'template' => Yii::t('app/ad', 'Template'),
            'created_at' => Yii::t('app/ad', 'Created At'),
            'updated_at' => Yii::t('app/ad', 'Updated At'),
            'created_by' => Yii::t('app/ad', 'Created By'),
            'updated_by' => Yii::t('app/ad', 'Updated By'),
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function behaviors()
    {
        $behaviors = parent::behaviors();

        $behaviors[] = [
            'class' => TimestampBehavior::className(),
            'createdAtAttribute' => 'created_at',
            'updatedAtAttribute' => 'updated_at',
            'value' => new \yii\db\Expression('NOW()'),
        ];
    
        $behaviors[] = [
            'class' => UserRecordBehavior::className(),
            'createdByAttribute' => 'created_by',
            'updatedByAttribute' => 'updated_by',
        ];
    
        return $behaviors;
    }
}
